#!/bin/bash
set -euo pipefail
scriptdir=$(cd $(dirname $0) && pwd)

export NODE_OPTIONS="--max-old-space-size=6144 ${NODE_OPTIONS:-}"

echo "************************************************************"
echo " buildup usage:"
echo " - execute 'buildup --resume' to resume after failure"
echo " - execute 'buildup' to restart the build from the start"
echo ""
echo " for advanced usage, see ${scriptdir}/foreach.sh"
echo "************************************************************"

if [ "$#" -eq 0 ]; then
  ${scriptdir}/foreach.sh --reset --up yarn build
else
  if [ "$1" != "--resume" ]; then
    echo "Unknown option: $1"
    exit 1
  fi
  ${scriptdir}/foreach.sh --up yarn build
fi

echo "************************************************************"
echo "buildup done"
echo "************************************************************"
